package com.wmyg.antifake.controller;

import com.wmyg.antifake.entity.ProductTag;
import com.wmyg.antifake.service.ProductTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;
import java.util.List;

/**
 * @author 王卓逸
 * @program TODO
 * @description TODO
 * @create 2019-06-05
 */
@RestController
@RequestMapping(value = "/producttag")
public class ProductTagController {

    @Autowired
    ProductTagService productTagService;

    @PostMapping(value = "/producttag")
    public Boolean saveProductTag(ProductTag productTag, Principal principal) {
        return productTagService.saveTag(productTag, principal.getName());
    }

    @PutMapping(value = "/producttag")
    public Boolean updateProductTag(ProductTag productTag) {
        return productTagService.updateTag(productTag);
    }

    @GetMapping(value = "/producttags")
    public List<ProductTag> getProductTagList(Principal principal) {
        return productTagService.findProductTagList(principal.getName());
    }

    @GetMapping(value = "/producttagpage")
    public Page<ProductTag> getProductTagPage(Integer index, Principal principal) {
        return productTagService.findProductTagPage(principal.getName(), index);
    }

    @GetMapping(value = "/producttag")
    public ProductTag getProductTag(Integer tagId) {
        return productTagService.findById(tagId);
    }

    @DeleteMapping(value = "/producttag")
    public Boolean deleteProductTag(Integer tagId) {
        return productTagService.delete(tagId);
    }

}
